package com.wangzaiplus.test.juc.thread.scheduledexecutor;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * @ClassName ScheduledExecutorDemo1
 * @Description: TODO
 * @Author wgc
 * @Date 2020/06/30 10:46
 * @Version V1.0
 **/
public class ScheduledExecutorDemo1 {
    public static void main(String[] args){
        System.out.println(System.currentTimeMillis());
        ScheduledExecutorService scheduledExecutorService =   Executors.newScheduledThreadPool(10);
        scheduledExecutorService.schedule(()->{
            System.out.println(System.currentTimeMillis() + "开始执行");
            //模拟任务耗时
            try {
                TimeUnit.SECONDS.sleep(3);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(System.currentTimeMillis() + "执行结束");
        }, 2, TimeUnit.SECONDS);
    }
}
